/*
 * @Author: evan.wan
 * @Date:   2016-06-25 15:55:20
 */

'use strict';
define([
    '../../common/service',
    'text!./tpl/uploadDialog.html',
    '../../common/ajaxfileupload'
], function(
    http,
    tpl
) {
    function me() {
        var self = this;
        this.init = function(callback) {
            self.callback = callback;
            self.$root = $('#upload-template-dialog');
            self.render();
        }

        this.render = function() {
            self.$root.html(I18N.parse(tpl, 'templateList'));
            self.event();
            self.$root.modal('show');
        }

        this.event = function() {
            //modal打开先请求元素数据
            self.$root.find('.btn-ok').off('click').on('click', $.proxy(self.confirmUpload, self));

            //self.getElement();
        }

        this.confirmUpload = function() {

            $.ajaxFileUpload({
                url: apiUrl + "/ectemplate/upload",
                fileElementId: 'file',
                type:'post',
                secureuri: false,
                dataType:'JSON',
                success: function (res, status) {
                    self.callback();
                    self.$root.modal('hide');
                }
            });
        }


    }
    return me;
});
